@{ViewBag.Title = "Paging";}
@section CssImport{<link href="@Url.Content("~/Scripts/validationEngine/validationEngine.jquery.css")" rel="stylesheet" type="text/css" />}
@section JavascriptImport{
<script type="text/javascript" src="@Url.Content("~/Scripts/validationEngine/jquery.validationEngine.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/validationEngine/jquery.validationEngine-en.js")"></script>}
<div class="filtering"><form>
<label>Introduzca texto para filtrar: <input type="text" name="filter" id="filter" title="Buscar o Filtrar por Descripcion"/></label>
<button type="submit" id="LoadRecordsButton" class="button medium orange" >Buscar Coincidencias</button>
</form></div>
<div id="MyTableContainer"></div>
<script type="text/javascript">
     $(document).ready(function () {
     $('#MyTableContainer').jtable({
         title: 'AIT_EquipoIT',
         paging: true,
         pageSize: 10,
         sorting: true,
         defaultSorting: 'Id ASC',
         actions: {
             listAction: '@Url.Action("JSONListaEquipos")',
             deleteAction: '@Url.Action("JSONDelete")',
             updateAction: '@Url.Action("JSONUpdate")',
             createAction: '@Url.Action("JSONCreate")'
         },
         fields:
         {
             Id: {
                 key: true,
                 create: false,
                 edit: false,
                 list: false
             }
             ,
             Guid: {
                 type : 'hidden'
             }
             ,
             Codigo: {
                 title: 'Codigo',
                 create: false,
                 edit: true,
                 list: true
             }
             ,
             CodigoSerialNumber: {
                 title: 'CodigoSerialNumber',
                 create: true,
                 edit: true,
                 list: true,
                 inputClass: 'validate[required]',
                 sorting: false
             }
             ,
             NumFactura: {
                 title: 'Factura',
                 create: true,
                 edit: true,
                 list: true,
                 sorting: false
             }
             ,
             Descripcion: {
                 title: 'Descripcion',
                 create: true,
                 edit: true,
                 list: true,
                 type: 'textarea'
             }
             ,
             EsEquipoCompuesto: {
                 defaultValue : false,
                 type: 'hidden'
             }             
            
             ,
             EsAccesorio: {
                 defaultValue: false,
                 type: 'hidden'
             },
             AplicaMantenimientoPreventivo: {
                 title: 'Mantener',
                 create: true,
                 edit: true,
                 list: true,
                 type: 'checkbox',
                 values: { 'false': 'No se aplica mantenimiento Preventivo', 'true': 'Aplicar Mantenimiento Preventivo' },
                 sorting: false
             }
             ,
             ModeloEquipoId_FK: {
                 title: 'Modelo',
                 create: true,
                 edit: true,
                 list: true,
                 options: '@Url.Action("../AIT_ModeloEquipo/JSONModelosEquipos")'
             }
            
             ,
             ProveedorId_FK: {
                 title: 'AIT_Proveedor',
                 create: true,
                 edit: true,
                 list: true,
                 options: '@Url.Action("../AIT_Proveedor/JSONGetElementsForDropDownList")'
             }
             ,
             Garantia: {
                 title: 'Garantia',
                 width: '60px',
                 sorting: false,
                 edit: false,
                 create: false,
                 listClass: 'child-opener-image-column',
                 display: function (equipoData) {
                     var $img = $('<img class="child-opener-image" with="20" height="20" src="@Url.Content("~/Content/images/menu/article.png")" title="Garantia" />');
                     //Open child table when user clicks the image
                     $img.click(function () {
                         $('#MyTableContainer').jtable('openChildTable',
                                    $img.closest('tr'),
                                    {
                                        title: 'Garantia del Equipo : ' + equipoData.record.Codigo,
                                        actions: {
                                            listAction: '@Url.Action("../AIT_Garantia/GarantiaEquipo")?equipoId=' + equipoData.record.Id,
                                            deleteAction: '@Url.Action("../AIT_Garantia/JSONDelete")',
                                            updateAction: '@Url.Action("../AIT_Garantia/JSONUpdate")',
                                            createAction: '@Url.Action("../AIT_Garantia/JSONCreate")'
                                        },
                                        fields: {
                                            EquipoId_FK: {
                                                type: 'hidden',
                                                defaultValue: equipoData.record.Id
                                            },
                                            Id: {
                                                key: true,
                                                create: false,
                                                edit: false,
                                                list: false
                                            }
                                            ,
                                            FechaInicio: {
                                                title: 'FechaInicio',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                type: 'date',
                                                displayFormat: 'dd-mm-yy',
                                                inputClass: 'validate[required]',
                                                sorting: false
                                            }
                                            ,
                                            FechaFin: {
                                                title: 'FechaFin',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                type: 'date',
                                                displayFormat: 'dd-mm-yy',
                                                inputClass: 'validate[required]',
                                                sorting: false
                                            }
                                            ,
                                            NumDocumentoGarantia: {
                                                type: 'hidden'
                                            }
                                            ,
                                            ProveedorId_FK: {
                                                title: 'AIT_Proveedor',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                options: '@Url.Action("../AIT_Proveedor/JSONGetElementsForDropDownList")'
                                            }
                                        }
                                    }, function (data) { //opened handler
                                        data.childTable.jtable('load');
                                    });
                     });
                     //Return image to show on the person row
                     return $img;
                 }
             }  
},
formCreated: function (event, data) {data.form.validationEngine();},
formSubmitting: function (event, data) {return data.form.validationEngine('validate');},
formClosed: function (event, data) { data.form.validationEngine('hide'); data.form.validationEngine('detach'); }
});
$('#LoadRecordsButton').click(function (e) {e.preventDefault();$('#MyTableContainer').jtable('load', {filter: $('#filter').val()});});
$('#LoadRecordsButton').click();
});
</script>

